#pragma once

#include <functional>
#include <mutex>
#include <string>
#include <condition_variable>

#include "Thread.h"
#include "noncopyable.h"

class EventLoop;

class EventLoopThread:noncopyable
{
public:
    using ThreadInitCallback = std::function<void(EventLoop*)>;

    EventLoopThread(const ThreadInitCallback& cb=ThreadInitCallback(),const std::string& name=std::string());
    ~EventLoopThread();

    EventLoop* startLoop();
private:
    void threadFunc();

    EventLoop* loop_;
    bool exiting_;
    Thread thread_;
    std::mutex mutex_;
    std::condition_variable cond_;
    // 提供一个自定义初始化的扩展点 允许用户在新线程的 EventLoop 启动事件循环前 注入自定义逻辑对其进行配置
    ThreadInitCallback callback_; 

};